  'use strict';
  import Base from './base.js';
  //美易通用户类类控制器请求方法
  module.exports = class extends Base {
  //请求获取用户信息
  async getuserinfoAction(){
    let user_id = this.get('user_id');
    let info = await this.model().query(' SELECT au.name,op.name as jobname,au.score,au.restday,au.headid,au.headurl,orz.name as zhichengname,au.username as tel FROM `think_or_app_user` au LEFT JOIN `think_or_position` op ON au.positionid = op.id LEFT JOIN `think_or_position` orz ON au.zhichengid = orz.id WHERE au.id = '+user_id+' ');
    if(think.isEmpty(info)){
    return this.json({'code':"200",'msg':"查询错误...",'data':info});
    }else{
    return this.json({'code':"100",'msg':"success...",'data':info});
    }
  }
  //请求获取当前用户的出勤情况
  async getuserworkAction(){
    let user_id = this.get('user_id');
    //获取今日开始的时间戳
    let time_start = Math.round(new Date(new Date().toDateString()).getTime()/1000);
    //今天结束时间
    let time_end = time_start + 86400;
    //查询数据库
    let info = await this.model('or_user_work').where({userid:user_id,time_start:{">=":time_start},time_end:{"<":time_end}}).find();
    //返回查询结果
    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"查找成功...",'data':info});
  }
  //请求更新当前用户头像
  async postuserheadAction(){
    let head_info = this.post();
    let info = await this.model('or_app_user').where({id:head_info.user_id}).update({headid:head_info.headid,headurl:head_info.headurl});
    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"查找成功...",'data':info});
  }
  //请求选择我服务的客户
  async getusermyfuwuguestAction(){
    let user_id = this.get('user_id');
    let res = this.model().query('SELECT * FROM `think_or_allotuser` oat LEFT JOIN `think_or_guest` og ON oat.gid = og.id WHERE oat.uid = '+user_id+' ');
    return think.isEmpty(res)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"查找成功...",'data':res});

  }
  //获取我的日程信息
  async getmymanagedayAction(){
    let user_id = this.get('user_id');
    let year = this.get('year');
    let month = this.get('month');
    let day = this.get('day');
    let info = await this.model().query(' SELECT * FROM `think_or_user_manage_day` WHERE year = '+year+' AND month = '+month+' AND day = '+day+'  AND userid = '+user_id+' ');
    return think.isEmpty(info)?this.json({'code':"200",'msg':"未找到日程...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info});
  }
  //加入特殊日期到我的日程中
  async postaddspecialdaymanageAction(){
    let year = this.post('year');
    let month = this.post('month');
    let day = this.post('day');
    let user_id = this.post('user_id');
    let remark = this.post('remark');
    let info = await this.model('or_user_manage_day').add({'year':year,'month':month,'day':day,'userid':user_id,'remark':remark,'type':1});
    return think.isEmpty(info)?this.json({'code':"200",'msg':"执行失败...",'data':''}):this.json({'code':"100",'msg':"添加成功...",'data':info});
  }
  //删除我的日程
  async postdelmanagedayAction(){
    let id = this.post('id');
    let res = await this.model('or_user_manage_day').where({id:id}).delete();
    return think.isEmpty(res)?this.json({'code':"200",'msg':"删除失败...",'data':''}):this.json({'code':"100",'msg':"删除成功...",'data':''});
  }
  //获取当前用户下的下属员工
  async getmyworkerAction(){
    let floor = this.get('floor');
    let jsonshop = this.get('jsonshop');
    let departmentid = this.get('departmentid');
    let ismanage = this.get('ismanage');
    switch(floor)
    {
      case '0':
      var info = await this.model().query(' SELECT au.id,au.name,IFNULL(od.name,"总部") as shopname,op.name as positionname,op1.name as zhichengname FROM `think_or_app_user` au LEFT JOIN `think_or_department` od ON au.shopid = od.id LEFT JOIN `think_or_position` op ON au.positionid = op.id LEFT JOIN `think_or_position` op1 ON au.zhichengid = op1.id WHERE au.shopid in ('+jsonshop+') or au.departmentid = '+departmentid+' ');
       break;
       case '1':
      var info = await this.model().query(' SELECT au.id,au.name,IFNULL(od.name,"总部") as shopname,op.name as positionname,op1.name as zhichengname FROM `think_or_app_user` au LEFT JOIN `think_or_department` od ON au.shopid = od.id LEFT JOIN `think_or_position` op ON au.positionid = op.id LEFT JOIN `think_or_position` op1 ON au.zhichengid = op1.id WHERE au.shopid = '+jsonshop+' ');
       break;
       case '2':
      var info = await this.model().query(' SELECT au.id,au.name,IFNULL(od.name,"总部") as shopname,op.name as positionname,op1.name as zhichengname FROM `think_or_app_user` au LEFT JOIN `think_or_department` od ON au.shopid = od.id LEFT JOIN `think_or_position` op ON au.positionid = op.id LEFT JOIN `think_or_position` op1 ON au.zhichengid = op1.id WHERE au.bumenid = '+jsonshop+' ');
       break;
       case '3':
         if (ismanage == 1) {
         var info = await this.model().query(' SELECT au.id,au.name,IFNULL(od.name,"总部") as shopname,op.name as positionname,op1.name as zhichengname FROM `think_or_app_user` au LEFT JOIN `think_or_department` od ON au.shopid = od.id LEFT JOIN `think_or_position` op ON au.positionid = op.id LEFT JOIN `think_or_position` op1 ON au.zhichengid = op1.id WHERE au.xiaozuid = '+jsonshop+' ');
         }
       break;
    }

    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info});
  }
  //获取员工页面数据
  async getuserdataAction(){
    let user_id = this.get('user_id');
    //获取今日开始的时间戳
    let starttime = Math.round(new Date(new Date().toDateString()).getTime()/1000);
    //今天结束时间
    let endtime = starttime + 86400;
    //获取本月开始的时间戳
    var time_start_month =  Math.round(new Date(new Date().getFullYear(),new Date().getMonth(), 1).getTime()/1000);
    //本月结束时间
    var time_end_month = Math.round(new Date(new Date().getFullYear(),new Date().getMonth()+1, 1).getTime()/1000);
    //获取今年开始的时间戳
    var time_start_year =  Math.round(new Date(new Date().getFullYear(),0, 1).getTime()/1000);
    //今年结束时间
    var time_end_year =  Math.round(new Date(new Date().getFullYear()+1,0, 1).getTime()/1000); 
    //定义api获取地址
    const datapath = think.config('datapath');
    let getapi = this.controller(datapath+'/database');
    //获取员工信息
    let userinfo = await this.model().query(' SELECT org.jsonshop,od.floor,au.ismanage,au.departmentid FROM `think_or_app_user` au LEFT JOIN `think_or_department` od ON au.departmentid = od.id LEFT JOIN `think_or_rulegroup` org ON au.zhichengid = org.groupid WHERE au.id = '+user_id+' ');
    let floor = userinfo[0].floor.toString();
    let ismanage = userinfo[0].ismanage;
    if (floor == 0) {
      if(userinfo[0].jsonshop == ''){var jsonshop = 0}else{
      var jsonshop = userinfo[0].jsonshop;
      }
    } else {
      var jsonshop = userinfo[0].departmentid;
    }
    //今日出勤状态
    let res1 = await this.model().query('SELECT type FROM `think_or_user_work` WHERE time_start >= '+starttime+' AND time_start < '+endtime+' AND userid = '+user_id+' ');
    if(think.isEmpty(res1)){var todaywork = 0}else{ var todaywork = res1[0].type}
    //本月出勤天数
    let res2 = await this.model().query('SELECT count(id) as num FROM `think_or_user_work` WHERE time_start >= '+time_start_month+' AND time_start < '+time_end_month+' AND userid = '+user_id+' ');
    if(think.isEmpty(res2)){var monthworknum = 0}else{ var monthworknum = res2[0].num}
    //年度出勤天数
    let res3 = await this.model().query('SELECT count(id) as num FROM `think_or_user_work` WHERE time_start >= '+time_start_year+' AND time_start < '+time_end_year+' AND userid = '+user_id+' ');
    if(think.isEmpty(res3)){var yearworknum = 0}else{ var yearworknum = res3[0].num}
    //今日工资
    let res4 = await this.model().query('SELECT IFNULL(sum(money),0) as num FROM `think_or_shop_userbasepay` WHERE time >= '+starttime+' AND time < '+endtime+' AND userid = '+user_id+' ')
    if(think.isEmpty(res3)){var todaymoney = 0}else{ var todaymoney = res4[0].num}
    //本月工资
    let res5 = await this.model().query('SELECT IFNULL(sum(money),0) as num FROM `think_or_shop_userbasepay` WHERE time >= '+time_start_month+' AND time < '+time_end_month+' AND userid = '+user_id+' ')
    if(think.isEmpty(res5)){var monthmoney = 0}else{ var monthmoney = res5[0].num}
    //年度工资
    let res6 = await this.model().query('SELECT IFNULL(sum(money),0) as num FROM `think_or_shop_userbasepay` WHERE time >= '+time_start_year+' AND time < '+time_end_year+' AND userid = '+user_id+' ')
    if(think.isEmpty(res6)){var yearmoney = 0}else{ var yearmoney = res6[0].num}
    //获取今日现金业绩
    let todayxianjin = await getapi.getyejixianjin(starttime,endtime,floor,jsonshop,ismanage,user_id);//实际现金业绩
    //获取本月现金业绩
    let monthxianjin = await getapi.getyejixianjin(time_start_month,time_end_month,floor,jsonshop,ismanage,user_id);//实际现金业绩
    //获取年度现金业绩
    let yearxianjin = await getapi.getyejixianjin(time_start_year,time_end_year,floor,jsonshop,ismanage,user_id);//实际现金业绩
    //获取今日规划业绩
    let todayplan = await getapi.getyejiplanxianjin(starttime,endtime,floor,jsonshop,ismanage,user_id);//规划业绩
    //获取本月规划业绩
    let monthplan = await getapi.getyejiplanxianjin(time_start_month,time_end_month,floor,jsonshop,ismanage,user_id);//规划业绩
    //获取年度规划业绩
    let yearplan = await getapi.getyejiplanxianjin(time_start_year,time_end_year,floor,jsonshop,ismanage,user_id);//规划业绩

    // let kahao = await getapi.getyejikahao(starttime,endtime,floor,jsonshop,ismanage,user_id);//卡耗业绩

    return this.json({'code':"100",'msg':"没有数据...",'data':{'floor':floor,'jsonshop':JSON.parse(jsonshop),'ismanage':ismanage,'todaywork':todaywork,'monthworknum':monthworknum,'yearworknum':yearworknum,'todaymoney':todaymoney,'monthmoney':monthmoney,'yearmoney':yearmoney,'todayxianjin':todayxianjin,'monthxianjin':monthxianjin,'yearxianjin':yearxianjin,'todayplan':todayplan,'monthplan':monthplan,'yearplan':yearplan}})

  }
  //获取用户当月的出勤记录
  async getusermonthworkinfoAction(){
    let user_id = this.get('user_id');
    let start_time = this.get('start_time');
    let end_time = this.get('end_time');
    let res = await this.model().query(' SELECT * FROM `think_or_user_work` WHERE userid = '+user_id+' AND time_start >= '+start_time+' AND time_start < '+end_time+' ');
    return think.isEmpty(res)?this.json({'code':"200",'msg':"本月没有出勤数据...",'data':''}):this.json({'code':"100",'msg':"success...",'data':res});
  }
  //获取员工月份工资明细
  async getusermoneylistAction(){
    let user_id = this.get('user_id');
    let start_time_js = this.get('start_time_js');
    let end_time_js = this.get('end_time_js');
    //查询提成
    let info = await this.model().query(' SELECT type,sum(money) as money FROM `think_or_shop_userbasepay` WHERE userid = '+user_id+' AND category = 2 AND time >= '+start_time_js+' AND time < '+end_time_js+' GROUP BY type ');
    //查询基本工资
    let info1 = await this.model().query(' SELECT type,sum(money) as money FROM `think_or_shop_userbasepay` WHERE userid = '+user_id+' AND category = 1 AND time >= '+start_time_js+' AND time < '+end_time_js+' GROUP BY type ');
    //指标工资
    let info2 = await this.model().query(' SELECT type,sum(money) as money FROM `think_or_shop_userbasepay` WHERE userid = '+user_id+' AND category = 3 AND time >= '+start_time_js+' AND time < '+end_time_js+' GROUP BY type ');
    //奖金工资
    let info3 = await this.model().query(' SELECT type,sum(money) as money FROM `think_or_shop_userbasepay` WHERE userid = '+user_id+' AND category = 4 AND time >= '+start_time_js+' AND time < '+end_time_js+' GROUP BY type ');
    //福利工资
    let info4 = await this.model().query(' SELECT type,sum(money) as money FROM `think_or_shop_userbasepay` WHERE userid = '+user_id+' AND category = 5 AND time >= '+start_time_js+' AND time < '+end_time_js+' GROUP BY type ');
    //扣除工资
    let info5 = await this.model().query(' SELECT type,sum(money) as money FROM `think_or_shop_userbasepay` WHERE userid = '+user_id+' AND category = 6 AND time >= '+start_time_js+' AND time < '+end_time_js+' GROUP BY type ');

    return this.json({'code':"100",'msg':"查询成功...",'sale':info,'base':info1,'zhibiao':info2,'jiangjin':info3,'fuli':info4,'kouchu':info5});
  }
  //获取员工提成工资的列表
  async getusermoneysaleinfoAction(){
    let user_id = this.get('user_id');
    let start_time_js = this.get('start_time_js');
    let end_time_js = this.get('end_time_js');
    let category = this.get('category');
    let type = this.get('type');

    let info = await this.model().query(' SELECT osu.addtime as paytime,osu.orderid,og.name,osu.money,og.headurl,oso.addtime as ordertime,osu.remarks FROM `think_or_shop_userbasepay` osu LEFT JOIN `think_or_shop_order` oso ON osu.orderid = oso.id LEFT JOIN `think_or_guest` og ON oso.guestid = og.id WHERE osu.userid = '+user_id+' AND osu.category = '+category+' AND osu.type = '+type+' AND osu.addtime >= '+start_time_js+' AND osu.addtime < '+end_time_js+' ');

    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"查询成功...",'data':info});
  }
  //获取员工基本工资的列表
  async getusermoneyinfoAction(){
    let user_id = this.get('user_id');
    let start_time_js = this.get('start_time_js');
    let end_time_js = this.get('end_time_js');
    let category = this.get('category');
    let type = this.get('type');

    let info = await this.model().query(' SELECT addtime,money,remarks FROM `think_or_shop_userbasepay` WHERE userid = '+user_id+' AND category = '+category+' AND type = '+type+' AND time >= '+start_time_js+' AND time < '+end_time_js+' ');

    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"查询成功...",'data':info});
  }
  //获取今日员工的考勤状态
  async getuserkaoqinlistAction(){
    let departmentid = this.get('departmentid');
    let floor = this.get('floor');
    let start_time_js = this.get('start_time_js');
    let end_time_js = this.get('end_time_js');

    switch(floor)
    {
      case '0':
      case '1':
        var info = await this.model().query(' SELECT au.id,IFNULL(A.type,0) as type,au.name,au.headurl,au.sex,IFNULL(A.time_start,0) as time_start,IFNULL(A.time_end,0) as time_end,IFNULL(A.shenhe,0) as shenhe FROM `think_or_app_user` au LEFT JOIN (SELECT au.id,ouw.type,ouw.shenhe,time_start,time_end FROM `think_or_app_user` au LEFT JOIN `think_or_user_work` ouw ON au.id = ouw.userid WHERE ouw.time_start >= '+start_time_js+' AND ouw.time_start < '+end_time_js+' AND au.shopid in ('+departmentid+')) as A ON au.id = A.id WHERE au.shopid in ('+departmentid+') ');
      break;
      case '2':
        var info = await this.model().query(' SELECT au.id,IFNULL(A.type,0) as type,au.name,au.headurl,au.sex,IFNULL(A.time_start,0) as time_start,IFNULL(A.time_end,0) as time_end,IFNULL(A.shenhe,0) as shenhe FROM `think_or_app_user` au LEFT JOIN (SELECT au.id,ouw.type,ouw.shenhe,time_start,time_end FROM `think_or_app_user` au LEFT JOIN `think_or_user_work` ouw ON au.id = ouw.userid WHERE ouw.time_start >= '+start_time_js+' AND ouw.time_start < '+end_time_js+' AND au.bumenid = '+departmentid+' ) as A ON au.id = A.id WHERE au.bumenid = '+departmentid+' ');
      break;
      case '3':
        var info = await this.model().query(' SELECT au.id,IFNULL(A.type,0) as type,au.name,au.headurl,au.sex,IFNULL(A.time_start,0) as time_start,IFNULL(A.time_end,0) as time_end,IFNULL(A.shenhe,0) as shenhe FROM `think_or_app_user` au LEFT JOIN (SELECT au.id,ouw.type,ouw.shenhe,time_start,time_end FROM `think_or_app_user` au LEFT JOIN `think_or_user_work` ouw ON au.id = ouw.userid WHERE ouw.time_start >= '+start_time_js+' AND ouw.time_start < '+end_time_js+' AND au.xiaozuid = '+departmentid+' ) as A ON au.id = A.id WHERE au.xiaozuid = '+departmentid+' ');
      break;
    }

    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info});
  }
  //考勤审核时获取员工当日的考勤记录
  async getuserthisdayworkinfoAction(){
    let user_id = this.get('user_id');
    let start_time_js = this.get('start_time_js');
    let end_time_js = this.get('end_time_js');
    let info = await this.model().query(' SELECT id,name,headurl FROM `think_or_app_user` WHERE id = '+user_id+' ');
    let info1 = await this.model().query(' SELECT * FROM `think_or_user_work` WHERE userid = '+user_id+' AND time_start >= '+start_time_js+' AND time_start < '+end_time_js+' ');
    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"success...",'user':info,'work':info1});
  }
  //审核用户考勤
  async postusershenheworkAction(){
    let user_id = this.post('user_id');
    let start_time_js = this.post('start_time_js');
    let type = this.post('type');
    let add_money = this.post('add_money');
    let del_money = this.post('del_money');
    let remark = this.post('remark');
    let date = this.post('date');
    let name = this.post('name');
    let workid = this.post('workid');
    let add_rest = this.post('add_rest');
    let del_rest = this.post('del_rest');
    let addtime = Math.round(Date.now() / 1000);
    let model = this.model('or_user_work');
    try{
      await model.startTrans();
      var info = 0 ; var info1 = 0;
      if(type == 0){
        let jilu = '';
        if(del_money != 0){jilu = '扣除工资'+del_money+'元！'}
        if(think.isEmpty(workid)){
          info = await model.add({userid:user_id,type:0,time_start:start_time_js,shenhe:1,shenhe_type:type,remark:remark,shenhe_jilu:jilu,shenhe_time:addtime,shenhe_name:name}); 
        }else{ 
          info = await model.where({id:workid}).update({type:type,shenhe:1,shenhe_type:type,shenhe_name:name,shenhe_time:addtime,remark:remark,shenhe_jilu:jilu});
        }
        let remarks = date+'扣除缺勤工资！'
        if(del_money != 0){
         
          info1 = await this.model('or_shop_userbasepay').db(model.db()).add({userid:user_id,category:6,type:1,money:-del_money,remarks:remarks,orderid:0,addtime:addtime,time:addtime});
        }else{info1 = 1;}
      }

      if(type == 4){
        if(think.isEmpty(workid)){
          info = await model.add({userid:user_id,type:4,time_start:start_time_js,shenhe:1,shenhe_type:type,remark:remark,shenhe_time:addtime,shenhe_name:name});
          info1 = 1;
        }else{
          info = await model.where({id:workid}).update({type:type,shenhe:1,shenhe_type:type,shenhe_name:name,shenhe_time:addtime,remark:remark});
          info1 = 1;
        }
      }
      if(type == 7){
        let jilu = '增加调休天数'+add_rest+'天！,加班费'+add_money+'元';
        if(think.isEmpty(workid)){
          info = await model.add({userid:user_id,type:type,time_start:start_time_js,shenhe:1,shenhe_type:type,remark:remark,shenhe_jilu:jilu,shenhe_time:addtime,shenhe_name:name}); 
        }else{
          info = await model.where({id:workid}).update({type:type,shenhe:1,shenhe_type:type,shenhe_name:name,shenhe_time:addtime,remark:remark,shenhe_jilu:jilu}); 
        }
          let remarks = date+'加班费！'
          var res1 = await this.model('or_app_user').db(model.db()).where({id:user_id}).increment('restday',add_rest*2);
          if(add_money != 0){
          var res2 = await this.model('or_shop_userbasepay').db(model.db()).add({userid:user_id,category:4,type:3,money:add_money,remarks:remarks,orderid:0,addtime:addtime,time:addtime});
          }else{var res2 = 1}
          if(!think.isEmpty(res1) && !think.isEmpty(res2)){info1 = 1;}else{info1 = 0}
      }
      if(type == 2){
        let jilu = '';
        if(del_money != 0){jilu = '扣除工资'+del_money+'元！'}
        if(think.isEmpty(workid)){
          info = await model.add({userid:user_id,type:type,time_start:start_time_js,shenhe:1,shenhe_type:type,remark:remark,shenhe_jilu:jilu,shenhe_time:addtime,shenhe_name:name});
        }else{
          info = await model.where({id:workid}).update({shenhe:1,shenhe_type:type,shenhe_name:name,shenhe_time:addtime,remark:remark,shenhe_jilu:jilu}); 
        }
        let remarks = date+'扣除请假工资！'
        if(del_money != 0){
          info1 = await this.model('or_shop_userbasepay').db(model.db()).add({userid:user_id,category:6,type:2,money:-del_money,remarks:remarks,orderid:0,addtime:addtime,time:addtime});
        }else{info1 = 1}
      }
      if(type == 3){
        if(think.isEmpty(workid)){
          info = await model.add({userid:user_id,type:type,time_start:start_time_js,shenhe:1,shenhe_type:type,remark:remark,shenhe_time:addtime,shenhe_name:name});
          info1 = 1;
        }else{
          info = await model.where({id:workid}).update({type:type,shenhe:1,shenhe_type:type,shenhe_name:name,shenhe_time:addtime,remark:remark}); 
          info1 = 1;
        }
      }
      if(type == 5){
        let jilu = '减少调休天数'+del_rest+'天！';
        if(think.isEmpty(workid)){
          info = await model.add({userid:user_id,type:type,time_start:start_time_js,shenhe:1,shenhe_type:type,remark:remark,shenhe_jilu:jilu,shenhe_time:addtime,shenhe_name:name});
        }else{
          info = await model.where({id:workid}).update({type:type,shenhe:1,shenhe_type:type,shenhe_name:name,shenhe_time:addtime,remark:remark,shenhe_jilu:jilu}); 
        }
        info1 = await this.model('or_app_user').db(model.db()).where({id:user_id}).decrement('restday',del_rest*2);
      }
      console.log(info); console.log('--------'); console.log(info1); 
      if (!think.isEmpty(info) && !think.isEmpty(info1)) {
        await model.commit();
      } else {
        await model.rollback();
      }
    }catch(e){
      console.log(e);
      await model.rollback();
    }

    if(think.isEmpty(info) || think.isEmpty(info1)){return this.json({'code':"200",'msg':"审核失败...",'data':''});}else{return this.json({'code':"100",'msg':"success...",'data':''});}
  }
  //获取今日上班员工
  async gettodayworkAction(){
    let jsonshop = this.get('jsonshop');
    let floor = this.get('floor');
    let departmentid = this.get('departmentid');
    //获取今日开始的时间戳
    let time_start = Math.round(new Date(new Date().toDateString()).getTime()/1000);
    //今天结束时间
    let time_end = time_start + 86400;
    let info;

    switch(floor)
    {
      case '0':
        info = await this.model().query(' SELECT au.id,IFNULL(A.type,0) as type,au.name,au.headurl,au.sex,IFNULL(A.time_start,0) as time_start,IFNULL(A.time_end,0) as time_end,IFNULL(A.shenhe,0) as shenhe FROM `think_or_app_user` au LEFT JOIN (SELECT au.id,ouw.type,ouw.shenhe,time_start,time_end FROM `think_or_app_user` au LEFT JOIN `think_or_user_work` ouw ON au.id = ouw.userid WHERE ouw.time_start >= '+time_start+' AND ouw.time_start < '+time_end+' AND (au.shopid in ('+jsonshop+') OR au.departmentid = '+departmentid+' )) as A ON au.id = A.id WHERE au.shopid in ('+jsonshop+') OR au.departmentid = '+departmentid+' ');
      break;
      case '1':
        info = await this.model().query(' SELECT au.id,IFNULL(A.type,0) as type,au.name,au.headurl,au.sex,IFNULL(A.time_start,0) as time_start,IFNULL(A.time_end,0) as time_end,IFNULL(A.shenhe,0) as shenhe FROM `think_or_app_user` au LEFT JOIN (SELECT au.id,ouw.type,ouw.shenhe,time_start,time_end FROM `think_or_app_user` au LEFT JOIN `think_or_user_work` ouw ON au.id = ouw.userid WHERE ouw.time_start >= '+time_start+' AND ouw.time_start < '+time_end+' AND au.shopid = '+jsonshop+' ) as A ON au.id = A.id WHERE au.shopid = '+jsonshop+' ');
      break;
      case '2':
      info = await this.model().query(' SELECT au.id,IFNULL(A.type,0) as type,au.name,au.headurl,au.sex,IFNULL(A.time_start,0) as time_start,IFNULL(A.time_end,0) as time_end,IFNULL(A.shenhe,0) as shenhe FROM `think_or_app_user` au LEFT JOIN (SELECT au.id,ouw.type,ouw.shenhe,time_start,time_end FROM `think_or_app_user` au LEFT JOIN `think_or_user_work` ouw ON au.id = ouw.userid WHERE ouw.time_start >= '+time_start+' AND ouw.time_start < '+time_end+' AND au.bumenid = '+jsonshop+' ) as A ON au.id = A.id WHERE au.bumenid = '+jsonshop+' ');
      break;
      case '3':
        info = await this.model().query(' SELECT au.id,IFNULL(A.type,0) as type,au.name,au.headurl,au.sex,IFNULL(A.time_start,0) as time_start,IFNULL(A.time_end,0) as time_end,IFNULL(A.shenhe,0) as shenhe FROM `think_or_app_user` au LEFT JOIN (SELECT au.id,ouw.type,ouw.shenhe,time_start,time_end FROM `think_or_app_user` au LEFT JOIN `think_or_user_work` ouw ON au.id = ouw.userid WHERE ouw.time_start >= '+time_start+' AND ouw.time_start < '+time_end+' AND au.xiaozuid = '+jsonshop+' ) as A ON au.id = A.id WHERE au.xiaozuid = '+jsonshop+' ');
      break;
     
    }

    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info});
  }
  //获取今日出单员工列表
  async getsaleusertodayAction(){
    let jsonshop = this.get('jsonshop');
    let departmentid = this.get('departmentid')
    let floor = this.get('floor');
    //获取今日开始的时间戳
    let time_start = Math.round(new Date(new Date().toDateString()).getTime()/1000);
    //今天结束时间
    let time_end = time_start + 86400;
    let info;

    switch(floor)
    {
      case '0':
        info = await this.model().query('SELECT au.id,au.name,au.headurl,au.sex,IFNULL(A.num,0) as num FROM `think_or_app_user` au LEFT JOIN (SELECT osy.userid,IFNULL(count(osy.id),0) as num FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id WHERE osy.addtime >= '+time_start+' AND osy.addtime < '+time_end+' AND (au.shopid IN ('+jsonshop+') OR au.departmentid = '+departmentid+')  GROUP BY osy.userid) as A ON au.id = A.userid WHERE au.shopid in ('+jsonshop+') OR au.departmentid = '+departmentid+' ORDER BY A.num DESC ');
      break;
      case '1':
      info = await this.model().query('SELECT au.id,au.name,au.headurl,au.sex,IFNULL(A.num,0) as num FROM `think_or_app_user` au LEFT JOIN (SELECT userid,IFNULL(count(id),0) as num FROM `think_or_shop_yejiticheng` WHERE addtime >= '+time_start+' AND addtime < '+time_end+' AND shopid = '+jsonshop+' GROUP BY userid) as A ON au.id = A.userid WHERE au.shopid = '+jsonshop+' ORDER BY A.num DESC ');
      break;
      case '2':
        info = await this.model().query('SELECT au.id,au.name,au.headurl,au.sex,IFNULL(A.num,0) as num FROM `think_or_app_user` au LEFT JOIN (SELECT userid,IFNULL(count(id),0) as num FROM `think_or_shop_yejiticheng` WHERE addtime >= '+time_start+' AND addtime < '+time_end+' AND bumenid= '+jsonshop+' GROUP BY userid) as A ON au.id = A.userid WHERE au.bumenid = '+jsonshop+' ORDER BY A.num DESC ');
      break;
      case '3':
        info = await this.model().query('SELECT au.id,au.name,au.headurl,au.sex,IFNULL(A.num,0) as num FROM `think_or_app_user` au LEFT JOIN (SELECT userid,IFNULL(count(id),0) as num FROM `think_or_shop_yejiticheng` WHERE addtime >= '+time_start+' AND addtime < '+time_end+' AND xiaozuid= '+jsonshop+' GROUP BY userid) as A ON au.id = A.userid WHERE au.xiaozuid = '+jsonshop+' ORDER BY A.num DESC ');
      break;
    }

    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info});
  }
  //获取今日已服务的客户
  async getguestfuwutodayAction(){
    let jsonshop = this.get('departmentid');
    let floor = this.get('floor');
    let ismanage = this.get('ismanage');
    let user_id = this.get('user_id');
    //获取今日开始的时间戳          
    let starttime = Math.round(new Date(new Date().toDateString()).getTime()/1000);
    //今天结束时间
    let endtime = starttime + 86400;
    let info;

    switch(floor)
    {
      case '0':
      case '1':
        info = await this.model().query(' SELECT og.name,og.id,count(og.id) as num,og.headurl,og.sex,og.arrivetime FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id LEFT JOIN `think_or_guest` og ON osy.guestid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+' AND au.shopid IN ('+jsonshop+') GROUP BY osy.guestid  ');
      break;
      case '2':
        info = await this.model().query(' SELECT og.name,og.id,count(og.id) as num,og.headurl,og.sex,og.arrivetime FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id LEFT JOIN `think_or_guest` og ON osy.guestid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+' AND au.bumenid = '+jsonshop+' GROUP BY osy.guestid ');
      break;
      case '3':
        if (ismanage == 1) {
          info = await this.model().query(' SELECT og.name,og.id,count(og.id) as num,og.headurl,og.sex,og.arrivetime FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id LEFT JOIN `think_or_guest` og ON osy.guestid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+' AND au.xiaozuid = '+jsonshop+' GROUP BY osy.guestid ');
        } else if (ismanage == 0) {
          info = await this.model().query('SELECT og.name,og.id,count(og.id) as num,og.headurl,og.sex,og.arrivetime FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id LEFT JOIN `think_or_guest` og ON osy.guestid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+' AND au.id = '+user_id+' GROUP BY osy.guestid ');
        }
      break;
    }

    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info});
  }
  //获取几日销售业绩分类
  async getdongtaixianjintodayAction(){
    let jsonshop = this.get('departmentid');
    let floor = this.get('floor');
    let ismanage = this.get('ismanage');
    let user_id = this.get('user_id');
    let starttime = this.get('start_time_js');
    let endtime = this.get('end_time_js');
    let info;
        switch(floor)
        {
          case '0':
          case '1':
            info = await this.model().query(' SELECT au.id,au.name,au.headurl,au.sex,IFNULL(sum(osy.xianjinyeji),0) as feat FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+' AND osy.xianjinyeji <> 0 AND au.shopid IN ('+jsonshop+') GROUP BY osy.userid ');
          break;
          case '2':
            info = await this.model().query(' SELECT au.id,au.name,au.headurl,au.sex,IFNULL(sum(osy.xianjinyeji),0) as feat FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+'  AND osy.xianjinyeji <> 0 AND au.bumenid = '+jsonshop+' GROUP BY osy.userid ');
          break;
          case '3':
            if (ismanage == 1) {
              info = await this.model().query(' SELECT au.id,au.name,au.headurl,au.sex,IFNULL(sum(osy.xianjinyeji),0) as feat FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+'  AND osy.xianjinyeji <> 0 AND au.xiaozuid = '+jsonshop+' GROUP BY osy.userid ');
            }
          break;
        }
    
        return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info});
  }
  //获取几日卡耗业绩分类
  async getdongtaixiaohaotodayAction(){
    let jsonshop = this.get('departmentid');
    let floor = this.get('floor');
    let ismanage = this.get('ismanage');
    let user_id = this.get('user_id');
    let starttime = this.get('start_time_js');
    let endtime = this.get('end_time_js');
    let info;
        switch(floor)
        {
          case '0':
          case '1':
            info = await this.model().query(' SELECT au.id,au.name,au.headurl,au.sex,IFNULL(sum(osy.kahaoyeji),0) as feat FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+' AND osy.kahaoyeji <> 0 AND au.shopid IN ('+jsonshop+') GROUP BY osy.userid ');
          break;
          case '2':
            info = await this.model().query(' SELECT au.id,au.name,au.headurl,au.sex,IFNULL(sum(osy.kahaoyeji),0) as feat FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+'  AND osy.kahaoyeji <> 0 AND au.bumenid = '+jsonshop+' GROUP BY osy.userid ');
          break;
          case '3':
            if (ismanage == 1) {
              info = await this.model().query(' SELECT au.id,au.name,au.headurl,au.sex,IFNULL(sum(osy.kahaoyeji),0) as feat FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_app_user` au ON osy.userid = au.id WHERE osy.addtime >= '+starttime+' AND osy.addtime < '+endtime+'  AND osy.kahaoyeji <> 0 AND au.xiaozuid = '+jsonshop+' GROUP BY osy.userid ');
            }
          break;
        }
    
        return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info});
  }
  //获取当前用户的现金业绩组成
  async getuserxianjinlistAction(){
    let user_id = this.get('user_id');
    let start_time = this.get('start_time_js');
    let end_time = this.get('end_time_js');
    let info = await this.model().query(' SELECT og.id,og.name,og.headurl,og.sex,sum(osy.xianjinyeji) as feat FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_guest` og ON osy.guestid = og.id WHERE osy.userid = '+user_id+' AND osy.addtime >= '+start_time+' AND osy.addtime < '+end_time+' AND osy.xianjinyeji <> 0 GROUP BY osy.guestid ');
    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"查询成功...",'data':info});
  }
  //获取当前用户的现金业绩组成
  async getuserkahaolistAction(){
    let user_id = this.get('user_id');
    let start_time = this.get('start_time_js');
    let end_time = this.get('end_time_js');
    let info = await this.model().query(' SELECT og.id,og.name,og.headurl,og.sex,sum(osy.kahaoyeji) as feat FROM `think_or_shop_yejiticheng` osy LEFT JOIN `think_or_guest` og ON osy.guestid = og.id WHERE osy.userid = '+user_id+' AND osy.addtime >= '+start_time+' AND osy.addtime < '+end_time+' AND osy.kahaoyeji <> 0 GROUP BY osy.guestid ');
    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"查询成功...",'data':info});
  }
  //检查该员工当日是否有报表
  async getthisuserdaysheetAction(){
    let user_id = this.post('user_id');
    let start_time = this.post('start_time_js');
    let end_time = this.post('end_time_js');
    let info = await this.model().query(' SELECT oud.id,au.name,oud.addtime,au.headurl FROM `think_or_user_daysheet` oud LEFT JOIN `think_or_app_user` au ON oud.userid = au.id WHERE oud.addtime > '+start_time+' AND oud.addtime < '+end_time+' AND userid = '+user_id+'  ');
    
    return think.isEmpty(info)?this.json({'code':"200",'msg':"没有数据...",'data':''}):this.json({'code':"100",'msg':"查询成功...",'data':info});
  }
  //完成某一个日程
  async postupdataonedayAction(){
    let id = this.post('id');
    let info = await this.model('or_user_manage_day').where({id:id}).update({type:2});
    return think.isEmpty(info)?this.json({'code':"200",'msg':"更新失败...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info}); 
  }
  //把某一个日程设置为未完成
  async postrestonedayAction(){
    let id = this.post('id');
    let info = await this.model('or_user_manage_day').where({id:id}).update({type:1});
    return think.isEmpty(info)?this.json({'code':"200",'msg':"更新失败...",'data':''}):this.json({'code':"100",'msg':"success...",'data':info}); 
  }

  
  //bottom
};